﻿using Manon.Core.Commons;
using Manon.Core.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Manon.Core.Filters
{
    public class ApiActionAsyncFilter : IAsyncActionFilter
    {
        public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var modelState = context.ModelState;
            if (!modelState.IsValid)
            {
                context.Result = new JsonResult(ApiResult.ErrorResult(context, ""));
            }
             
            return Task.CompletedTask;
        }
    }
}
